<?PHP
class ArticleBO extends BusinessObject{
  // Article types
  var $ARTICLE_SIMPLEARTICLE  = 0;
  var $ARTICLE_PHOTOALBUM     = 1;
  var $ARTICLE_BANNERS        = 2;
  var $ARTICLE_BLOCK          = 3;
  var $ARTICLE_POLL           = 4;
  var $ARTICLE_FORUM          = 5;
  var $ARTICLE_GUESTBOOK      = 6;
  var $ARTICLE_NEWS           = 7;
  var $ARTICLE_RSS            = 8;

  var $ARTICLE_TYPES = array (
    "article"	=> "0",
    "album"		=> "1",
    "banner"	=> "2",
/*    "block"		=> "3",
    "poll"		=> "4",
    "forum"		=> "5",
    "guestbook"	=> "6",
    "news"		=> "7",
    "rss"		=> "8"
*/
  );

  var $VIEW_STANDART	= 0;
  var $VIEW_ONE_COLUMN	= 1;
  var $VIEW_ONE_COLUMN2	= 3;
  var $VIEW_ONE_IMAGE	= 2;

  var $ARTICLE_TYPE_VIEW = array (
	"standart"	=> "0",
	"one_column"=> "1",
	"one_column2"=> "3",
	"one_image"	=> "2",
  );

  /* private function using in constructors*/ 
  function setAttributes(){
	$this->fields	= array(
		'id'		=> 'articleID',
		'name'		=> 'articleName',
		'date'		=> 'articleDate',
		'content'	=> 'articleContent',
		'short'		=> 'articleShort',
		'visible'	=> 'articleVisible',
		'folderID'	=> 'folderID',
		'langID'	=> 'articleLangID',
		'show_title'=> 'articleShowTitle',
		'type' 		=> 'articleType',
		'view_type'	=> 'articleViewType');
    BusinessObject::setAttributes();
  }

  function get_types_as_html($selected_typeID="0"){
	$aa = new ArticleBO();
	$ret = "";
	foreach($aa->ARTICLE_TYPES as $k => $v) {
	  $ret.= "<option value='{$aa->ARTICLE_TYPES[$k]}' ".(($selected_typeID==$aa->ARTICLE_TYPES[$k])?"selected":"").">".$k."</option>";
	}
	return $ret;
  }

  function get_type_view_as_html($selected_typeID="0"){
	$aa = new ArticleBO();
	$ret = "";
	foreach($aa->ARTICLE_TYPE_VIEW as $k => $v) {
	  $ret.= "<option value='{$aa->ARTICLE_TYPE_VIEW[$k]}' ".(($selected_typeID==$aa->ARTICLE_TYPE_VIEW[$k])?"selected":"").">".$k."</option>";
	}
	return $ret;
  }

  function get_article_type_view(){
	return $this->ARTICLE_TYPE_VIEW;
  }

  function get_article_types(){
	return $this->ARTICLE_TYPES;
  }

  function fillOtherEmptyLanguages($article)
  {
    $qq="INSERT INTO article (".$article->fields["id"].",".$article->fields["langID"].",".$article->fields["name"].",".$article->fields["date"].",".$article->fields["content"].",".$article->fields["visible"].",".$article->fields["folderID"].",".$article->fields["show_title"].",".$article->fields["type"].") ".
    		"SELECT $article->id,lang.langID,'".into_db($article->name).
    		"','".into_db($article->date).
    		"','".article_prepare_to_save($article->content).
    		"',".into_db($article->visible).
    		",".into_db($article->folderID).
    		",".into_db($article->show_title).
    		",".into_db($article->type).
    	  " FROM lang LEFT JOIN article AS art ON (art.articleLangID=lang.langID AND art.articleID=".$article->id.")".
        "WHERE art.articleLangID IS NULL AND lang.langVisible=1";
        $this->db->query($qq);
  }

  /* constructor */
  function ArticleBO(){
    /** super(tableName) */
    BusinessObject::BusinessObject("article");
    $this->setAttributes();
  }
}
?>
